﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Devices;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;
namespace Day2
{
    public partial class WhereAmI : PhoneApplicationPage
    {
        public WhereAmI()
        {
            InitializeComponent();
        }
        GeoCoordinateWatcher gps;

        private void myBingMap_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
            myBingMap.Center = new GeoCoordinate(13.7472, 100.5443);
            gps = new GeoCoordinateWatcher();
            gps.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gps_PositionChanged);
            gps.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(gps_StatusChanged);
            gps.Start();    
            
            //myBingMap.ZoomLevel = myBingMap.ZoomLevel * 10;
			
        }

        void gps_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            if (e.Status == GeoPositionStatus.Initializing) {
                MessageBox.Show("Init");
            }
            else if (e.Status == GeoPositionStatus.NoData) {
                MessageBox.Show("NoData");
            }
            else if (e.Status == GeoPositionStatus.Ready) {
                MessageBox.Show("Ready");
            }
            else if (e.Status == GeoPositionStatus.Disabled) {
                MessageBox.Show("Disable"); 
            }
        }

        void gps_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            if(gps.Status == GeoPositionStatus.Ready)
                myBingMap.Center =  e.Position.Location;
        }
    }
}
